package A002lock8;

import java.util.concurrent.TimeUnit;

// 1个静态同步方法,1个普通同步方法，1部手机，请问先打印邮件还是短信？
// -----sendSMS
// -----sendEmail

class Phone07 {
    public static synchronized void sendEmail() throws Exception {
        TimeUnit.SECONDS.sleep(4);
        System.out.println("-----sendEmail");
    }

    public synchronized void sendSMS() throws Exception {
        System.out.println("-----sendSMS");
    }
}

public class A002_线程八锁_7 {
    public static void main(String[] args) throws InterruptedException {

        Phone07 phone07 = new Phone07();

        new Thread(() -> {
            try {
                phone07.sendEmail();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }, "A").start();

        Thread.sleep(100);

        new Thread(() -> {
            try {
                phone07.sendSMS();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }, "B").start();
    }
}
